/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.phom.handler;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import extension.room.analyse.Card;
import extension.room.phom.PhomExtension;
import extension.room.phom.PhomGame;
import extension.room.phom.PhomPlayer;
import java.util.List;
import log.Debug;

/**
 *
 * @author daz
 */
public class ShowPhomHandler extends BaseClientRequestHandler {

    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        PhomExtension tienlenExtension = (PhomExtension) getParentExtension();
        PhomGame game = tienlenExtension.getGame();
        PhomPlayer p = game.getPlayerFight();

        if (p != null && !p.isIsShowPhom()) {
            if (p.getShowPhomOrder() >= 0) {
                if (p.getPhomType() == PhomPlayer.MAIN_PHOM) {
                    logShowPhom(user.getName(), p.getListPhom());
                    p.removePhom();
                    tienlenExtension.getResponse().notifyPhom(p.getHavePhom(), p.getListPhom(), p.getSeatPos());
                } else {
                    logShowPhom(user.getName(), p.getListSubPhom());
                    p.removeSubPhom();
                    tienlenExtension.getResponse().notifyPhom(p.getHavePhom(), p.getListSubPhom(), p.getSeatPos());
                }
                game.depositAction();
            }
        }
    }

    private void logShowPhom(String name, List<Integer> listPhom) {
        if (listPhom != null && !listPhom.isEmpty()) {
            StringBuilder builder = new StringBuilder();
            for (Integer card : listPhom) {
                builder.append(Card.getName(card));
                builder.append(",");
            }
            Debug.d(name + "-show phom:" + builder.toString());
        } else {
            Debug.d(name + "-show phom: not have phom");
        }
    }
}
